﻿package mortal.game.scene3D.layer3D
{
    import __AS3__.vec.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.mvc.core.*;

    public class EntityTalkLayer extends UILayer
    {
        protected var entityList:Vector.<IEntity>;
        private var _isNPCWindowShow:Boolean = false;

        public function EntityTalkLayer()
        {
            this.entityList = new Vector.<IEntity>;
            Dispatcher.addEventListener(EventName.NPCDialogWindowShow, this.onNPCDialogWindowShow);
            Dispatcher.addEventListener(EventName.NPCDialogWindowHide, this.onNPCDialogWindowHide);
            return;
        }// end function

        private function onNPCDialogWindowShow(event:DataEvent) : void
        {
            this._isNPCWindowShow = true;
            this.updateLayerVisible();
            return;
        }// end function

        private function onNPCDialogWindowHide(event:DataEvent) : void
        {
            this._isNPCWindowShow = false;
            this.updateLayerVisible();
            return;
        }// end function

        private function updateLayerVisible() : void
        {
            this.visible = !this._isNPCWindowShow;
            return;
        }// end function

        public function addTalk(param1:IEntity, param2:String, param3:int = 5000) : void
        {
            if (!param1)
            {
                return;
            }
            var _loc_4:* = this.entityList.indexOf(param1);
            if (_loc_4 < 0)
            {
                this.entityList.push(param1);
            }
            param1.talk(param2, param3);
            return;
        }// end function

        public function removeTalk(param1:IEntity) : void
        {
            var _loc_2:* = this.entityList.indexOf(param1);
            if (_loc_2 >= 0)
            {
                this.entityList.splice(_loc_2, 1);
            }
            param1.clearTalk();
            return;
        }// end function

        public function updateTalkPosition() : void
        {
            var _loc_1:* = this.entityList.length;
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this.entityList[_loc_2].updateTalkXY();
                _loc_2++;
            }
            return;
        }// end function

        public function clear() : void
        {
            this.entityList = new Vector.<IEntity>;
            return;
        }// end function

    }
}
